/*
 * Sketch_oct31b_aliyun.h
 */
#ifndef SKETCH_OCT31B_ALIYUN_H
#define SKETCH_OCT31B_ALIYUN_H
#include "Arduino.h"
/****************************************ALiyun part****************************************/
/******************产品/设备配置(每个人需要根据自己的产品设备信息去动态更换)**********************/
/* 设置产品和设备的信息，从阿里云设备信息里查看
/*
{
  "ProductKey": "a1yJwf7XIoU",
  "DeviceName": "ESP8266-tmp-01",
  "DeviceSecret": "0b4631600f778a6a6b3936e5d1763b8b"
}
*/
#include <ESP8266WiFi.h>
//for 支持Json数据格式的头文件
#include <ArduinoJson.h>
//for 阿里云SDK的头文件
#include <AliyunIoTSDK.h>
//for 发布/订阅功能的头文件
#include <PubSubClient.h>
// Aliyun WIFI --------------------------------------------------------------------------------------
// #define PRODUCT_KEY "a1yJwf7XIoU"
// #define DEVICE_NAME "ESP8266-tmp-01"
// #define DEVICE_SECRET "0b4631600f778a6a6b3936e5d1763b8b"
// #define REGION_ID "cn-shanghai"
// #define MQTT_SERVER PRODUCT_KEY ".iot-as-mqtt." REGION_ID ".aliyuncs.com"  //阿里云MQTT服务地址
// #define MQTT_PORT 1883
// #define HTTPS_SERVER "iot-auth." REGION_ID ".aliyuncs.com"  //认证地址
// #define HTTPS_PORT 443
// // 相关主题
// // #define TOPIC_SET_PROPERTY "/sys/" PRODUCT_KEY "/{dName}/thing/service/property/set"
// #define TOPIC_SET_PROPERTY "/sys/" PRODUCT_KEY "/{dName}/thing/service/property/set"
class Sketch_oct31b_aliyun {
private:
  char PRODUCT_KEY[20] = "a1yJwf7XIoU";
  char DEVICE_NAME[40] = "ESP8266-tmp-01";
  char DEVICE_SECRET[40] = "0b4631600f778a6a6b3936e5d1763b8b";
  char REGION_ID[20] = "cn-shanghai";
  char API_KEY[20] = "Your ApiKey";
  int MQTT_PORT = 1883;
  int HTTPS_PORT = 443;
  String HTTPS_SERVER = "";        //认证地址
  String MQTT_SERVER = "";         //阿里云MQTT服务地址
  String TOPIC_SET_PROPERTY = "";  // 相关广播主题
  // void powerCallback(JsonVariant p);
  int aliyunTimeInterval = 3 * 1000;
  unsigned long cal_delayStart = 0;  // the time Aaliyun delay started
  struct aliyun_config {
    char product_key[20];
    char device_name[40];
    char device_secret[40];
    char region_id[20];
  } aliyunConfig;
  struct aliyun_data {
    char currentInSideTemperatureA[20] = "-1";  // 当前温度
    char currentOutSideTemperatureB[20] = "-1";
    char currentHumidity[20] = "101";  // 当前湿度
    char ch2o[20] = "500";             // 二氧化碳浓度
    char tds[20] = "1000";             // 当前液体浑浊度
  } aliyunData;
public:
  // ----- Constructor -----
  Sketch_oct31b_aliyun();
  ~Sketch_oct31b_aliyun();

  void initAliyunManager(WiFiClient espClient);

  void upload2Aliyun(String str_monitor, long _interval);
};
#endif